package com.example.performance.jol.official;

import org.openjdk.jol.info.ClassLayout;
import org.openjdk.jol.vm.VM;

/**
 * @author Aleksey Shipilev
 */
@SuppressWarnings({"java:S101", "java:S106"})
public class JOLSample_08_Class {

    /*
     * Another example of special treatment for some fields.
     *
     * If you run this example, you can see the large gap in instance field block.
     * There are no Java fields that could claim that block, hence there are no
     * "hidden" fields, like in the example before. This time, VM "injects" some
     * of the fields into the Class, to store some of the meta-information there.
     *
     * See:
     *  https://github.com/openjdk/jdk/blob/fd45694c58452635db572cb55e5a1b2cb7bc34b2/src/hotspot/share/classfile/javaClasses.hpp#L219-L226
     *
     * #define CLASS_INJECTED_FIELDS(macro)                                       \
     *   macro(java_lang_Class, klass,                  intptr_signature,  false) \
     *   macro(java_lang_Class, array_klass,            intptr_signature,  false) \
     *   macro(java_lang_Class, oop_size,               int_signature,     false) \
     *   macro(java_lang_Class, static_oop_field_count, int_signature,     false) \
     *   macro(java_lang_Class, protection_domain,      object_signature,  false) \
     *   macro(java_lang_Class, signers,                object_signature,  false) \
     *   macro(java_lang_Class, source_file,            object_signature,  false) \
     *
     *   total 28 bytes gap:   4 * 7 = 28
     */

    public static void main(String[] args) {
        System.out.println(VM.current().details());
        System.out.println(ClassLayout.parseClass(Class.class).toPrintable());
    }

}